package org.vectrics.domain;

import java.io.Serializable;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import org.vectrics.common.db.RecordObject;
import org.vectrics.common.db.Voidable;
import org.vectrics.company.Company;

public class Domain implements RecordObject, Voidable, Serializable {
	public static final long serialVersionUID = 801642690324L;
	private Long id = null;
	private String description = null;
	private boolean voided = false;
	private Domain parent = null;
	private Company primaryCompany = null;
	private Set children = new HashSet();
	
	public Domain() {
		super();
	}

	/**
	 * @return Returns the id.
	 */
	public Long getId() {
		return id;
	}

	/**
	 * @param id The id to set.
	 */
	public void setId(Long id) {
		this.id = id;
	}


	
	public Set retrieveChildrenInBranch() {
		Set resultSet = new HashSet();
		resultSet.addAll(this.getChildren());
		Iterator iter = this.getChildren().iterator();
		while (iter.hasNext()) {
			Domain childDomain = (Domain)iter.next();
			resultSet.addAll(childDomain.retrieveChildrenInBranch());
		}
		return(resultSet);
	}
	
	
	/**
	 * @return Returns the primaryCompany.
	 */
	public Company getPrimaryCompany() {
		return primaryCompany;
	}

	/**
	 * @param primaryCompany The primaryCompany to set.
	 */
	public void setPrimaryCompany(Company primaryCompany) {
		this.primaryCompany = primaryCompany;
	}

	/**
	 * @return Returns the parent.
	 */
	public Domain getParent() {
		return parent;
	}

	/**
	 * @param parent The parent to set.
	 */
	public void setParent(Domain parent) {
		this.parent = parent;
	}

	/**
	 * @return Returns the description.
	 */
	public String getDescription() {
		return description;
	}


	/**
	 * @param description The description to set.
	 */
	public void setDescription(String description) {
		this.description = description;
	}
	
	/**
	 * @return Returns the children.
	 */
	public Set getChildren() {
		return children;
	}

	/**
	 * @param children The children to set.
	 */
	public void setChildren(Set children) {
		this.children = children;
	}

	/**
	 * @return Returns the voided.
	 */
	public boolean getVoided() {
		return voided;
	}

	/**
	 * @param voided The voided to set.
	 */
	public void setVoided(boolean voided) {
		this.voided = voided;
	}

	
	public String toString() {
		return(this.id + "|" + this.description);
	}
}
